/**
 * 消息页
 */
import React, { PureComponent } from "react";
import { StyleSheet, Text, View, ScrollView } from "react-native";
import actions from "../../models/actions";
import NavigationBar from "../../components/navigationBar";
import { connect } from "react-redux";
import { safeAreaBottomHeight } from "../../util/AdapterUtil";
import * as requestApi from "../../util/requestApi";

class ServiceAgreementScreen extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      agreement: ""
    };
  }

  componentDidMount() {
    this.getAgreementInfo();
  }

  render() {
    return (
      <View style={{ flex: 1, backgroundColor: "#fff" }}>
        <NavigationBar
          navigation={this.props.navigation}
          isBack={true}
          title={"服务协议"}
        />
        <ScrollView
          showsVerticalScrollIndicator={false}
          style={{ width: "100%", backgroundColor: "#fff" }}
        >
          <View style={{ height: 10, backgroundColor: "#F9F9F9" }} />

          <Text
            style={{
              marginLeft: 15,
              color: "#202020",
              fontSize: 16
            }}
          >
            服务协议：
          </Text>

          <Text
            style={{
              marginTop: 15,
              marginBottom: 15,
              marginLeft: 15,
              marginRight: 15,
              color: "#202020",
              fontSize: 14
            }}
          >
            {this.state.agreement}
          </Text>
        </ScrollView>
        <View style={{ height: safeAreaBottomHeight }} />
      </View>
    );
  }

  //获取服务协议的文字
  getAgreementInfo() {
    //
    let params = { protocolId: 1 };
    requestApi
      .queryUserProtocal(params)
      .then(res => {
        if (res.content) {
          this.setState({
            agreement: res.content
          });
        } else {
          Toast.show("网络请求失败", 1000);
        }
      })
      .catch(err => {
        Toast.show(err.msg, 1000);
      });
  }
}

const styles = StyleSheet.create({});

export default connect(
  ({ userInfo }) => ({
    userInfo
  }),
  {}
)(ServiceAgreementScreen);
